package com.lvt.design.pattern.create.single.demo02;

import java.util.concurrent.atomic.AtomicLong;

/**
 * desc：class
 * 懒汉式
 *
 * @author LT
 * @date 2022/11/30
 */
public class IdGenerator {

    private AtomicLong id = new AtomicLong(0);
    private static IdGenerator instance;

    private IdGenerator() {
    }

    public static synchronized IdGenerator getInstance() {
        if (instance == null) {
            return new IdGenerator();
        }
        return instance;
    }

    public Long getId() {
        return id.incrementAndGet();
    }

}
